package com.pwt.repository;

import com.pwt.common.ResultPage;
import com.pwt.entity.MachineManage;
import com.pwt.model.MachineManageModel;
import com.pwt.repository.base.DataRepositoryExtension;
import org.apache.commons.lang3.StringUtils;

/**
 * @author dw
 * @version 1.0.0
 * @date 2021/9/1
 */
public class MachineManageRepositoryExtensionImpl extends DataRepositoryExtension<MachineManage,String> implements  MachineManageRepositoryExtension{

    @Override
    public ResultPage<MachineManageModel> getList(String name, Integer offset, Integer limit) {
        String sql = " SELECT m.MAMASCHINE mId,m.MANR as mNumber,m.MABEZ mName,p.PRPRUEFER pId,p.PRNAME pNumber,p.PRVORNAME pName" +
                " from MASCHINE m\n" +
                " left JOIN ZU_MA_MAk z on m.MAMASCHINE =z.MAkEY\n" +
                " LEFT JOIN MASCHINkAT ma on ma.MAkNR=z.MAkNR\n" +
                " LEFT JOIN PRUEFER p on p.PRNAME = ma.MAkBEZ ";
        String cSql ="SELECT count(1)  from  MASCHINE  ";
        if(name != null && StringUtils.isNotBlank(name)){
            sql += " where  m.MANR like N'%"+name+"%'  or m.MABEZ like N'%"+name+"%' ";
            cSql += " where  MANR like N'%"+name+"%'  or MABEZ like N'%"+name+"%' ";
        }

        return super.queryCustomBeanPageBySql(MachineManageModel.class,cSql,sql,offset-1,limit);
    }
}
